home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -websites- / wirenet / files / thor25_arexx.lha / MailtoScripts / AWebMailTo.thor < prev    next >
Text File  |  1996-09-26  |  8KB  |  250 lines

  1. /*
  2. ** $VER: AwebMailTo.thor v1.33 (29.07.96) Shaun Downend.
  3. **              <shaund@amiganut.demon.co.uk>
  4. **
  5. ** This is a very simple script designed for use with AWeb's mailto:
  6. ** support. It will take the email address supplied by AWeb and start
  7. ** a text editor of your choice and automatically fill in the To: field.
  8. ** When you have finished you save the message and it will appear as an
  9. ** event in Thor.
  10. **
  11. ** Configuration in AWeb (1.2b) :-
  12. **
  13. ** Unfortunately it appears that AWeb does not inherit the DOS path, that
  14. ** is why I have used the full path of RX below.
  15. **
  16. **      Enter Change Settings.
  17. **
  18. **      Network3:  External programs
  19. **      Type:      mailto:
  20. **      Command:   sys:rexxc/rx
  21. **      Arguments: Thor:rexx/AWebMailTo.thor %s
  22. **
  23. ** Configuration in this script:-
  24. **
  25. ** MailSystem is the name of your TCP system in THOR, and MailConfName is
  26. ** obviously the name of your email conference in THOR.
  27. **
  28. ** Setting AddSignature to 'Y' will make AwebMailTo.thor read your conference/
  29. ** BBS/global signature settings and add that signature to your mails.
  30. **
  31. ** Set Editor to the text editor of your choice.
  32. **
  33. ** Sending a mailto: with AWeb should now produce an EnterMsg event in THOR.
  34. ** The mail will be sent the next time you use Send Events from ConnectTHOR.
  35. **
  36. ** Note: THOR does not have to be running for this script to work!
  37. **
  38. ** History:
  39. ** ¯¯¯¯¯¯¯¯
  40. ** AWebMailTo.thor v1.1  (02.04.96) is based on SendMail.thor 1.10 by Troels
  41. **                                  Walsted Hansen.
  42. **                 v1.2  (18.06.96) Fixed to support ced which requires a
  43. **                                  larger stack than default. Temporary
  44. **                                  files were not deleted upon an error.
  45. **                 v1.3  (21.06.96) Added optional immediate sending of events.
  46. **                 v1.31 (10.07.96) Added support for Miami TCP/IP stack.
  47. **                       (23.07.96) Now uses Thor's TCP Systems config to
  48. **                                  find the mailserver address.
  49. **                 v1.32 (23.07.96) Now uses $thor/thorpath to find the path
  50. **                                  to Thor.
  51. **                 v1.33 (29.07.96) Fixed a stupid bug which was introduced in
  52. **                                  v1.32 would cause the script to error if
  53. **                                  AddSignature was set to 'N'.
  54. */
  55.  
  56. MailSystem = 'Internet'
  57. MailConfName = 'EMail'
  58. AddSignature = 'Y'              /* Add signature from Thor (Y/N) */
  59. SendEvent  = 'Y'                /* Send event immediately (Y/N)  */
  60.  
  61. Editor = 'c:ced -keepio'        /* insert '-pubscreen=AWeb' after -keepio for the editor    *
  62.                                  * to open on AWeb's public screen.                         */
  63.  
  64.                                 /* To use GoldED for your editor use the following          *
  65.                                  * Editor = 'c:ED STICKY CONFIG GOLDED:Config/AWeb.prefs'   */
  66.  
  67. /* DON'T CHANGE ANYTHING BELOW HERE */
  68.  
  69. Tempfile = 't:MailTo.msg.'||time(s)'.aweb'
  70.  
  71. parse arg argument
  72.  
  73. template = 'ADDRESS/A'
  74.  
  75. if(argument = '' | argument = '?') then
  76. do
  77.     say '$VER: AWebMailTo.thor V1.33 (29.07.96) Shaun Downend.'
  78.     say 'Template:' template
  79.     exit
  80. end
  81.  
  82. if ~show('p', 'BBSREAD') then
  83. do
  84.     address command
  85.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  86.     "sys:rexxc/WaitForPort BBSREAD"
  87. end
  88.  
  89.  
  90. address BBSREAD
  91.  
  92. READARGS template ARGS CMDLINE argument
  93. if(rc ~= 0) then
  94. do
  95.     say BBSREAD.LASTERROR
  96.     exit
  97. end
  98.  
  99. address command 'c:echo >'tempfile' "To: 'ARGS.ADDRESS'*NSubject: *N"'
  100. call pragma('s',8000)
  101. address command ''Editor' 'tempfile''
  102. call pragma('s',4096)
  103.  
  104. if(~OPEN(fh,tempfile,'Read')) then
  105. do
  106.     say 'Unable to open file'
  107.     exit
  108. end
  109.  
  110. str = readln(fh)
  111.  
  112. if(upper(word(str, 1)) ~= "TO:") then
  113. do
  114.     call showerror("First headerline wasn't a To:, please don't mess with the header AWeb provides.")
  115.     call close(fh)
  116.     address command 'c:delete >NIL: 'tempfile''
  117.     exit
  118. end
  119. else EVENT.TOADDR = word(str, 2)
  120.  
  121. str = readln(fh)
  122.  
  123. if(upper(word(str, 1)) ~= "SUBJECT:") then
  124. do
  125.     call showerror("Second headerline wasn't a Subject:, please don't mess with the header AWeb provides.")
  126.     call close(fh)
  127.     address command 'c:delete >NIL: 'tempfile''
  128.     exit
  129. end
  130. else EVENT.SUBJECT = substr(str, 10)
  131.  
  132. /* skip X-Mailer: line */
  133.  
  134. call readln(fh)
  135.  
  136. /* put the body of the message in a file with a unique name */
  137.  
  138. UNIQUEMSGFILE bbsname '"'MailSystem'"' stem UNIQUEFILE
  139. if(rc ~= 0) then
  140. do
  141.     call showerror('UNIQUEMSGFILE BBSRead command failed: ' || BBSREAD.LASTERROR)
  142.     call close(fh)
  143.     address command 'c:delete >NIL: 'tempfile''
  144.     exit
  145. end
  146.  
  147. call open(tmp, UNIQUEFILE.NAME, W)
  148.  
  149. do until eof(fh)
  150.     call writeln(tmp, readln(fh))
  151. end
  152.  
  153. /* add signature from the EMail conference/BBS/Global Settings */
  154.  
  155. if(upper(AddSignature) = 'Y') then
  156. do
  157.     GETCONFDATA BBSNAME '"'MailSystem'"' CONFNAME '"'MailConfName'"' STEM CONFD
  158.     if(CONFD.SIGNATURE = "") then
  159.     do
  160.         GETBBSDATA BBSNAME '"'MailSystem'"' STEM BBSD
  161.         if(BBSD.SIGNATURE = "") then
  162.         do
  163.             GETGLOBALDATA STEM GLOBD
  164.             if(GLOBD.SIGNATURE = "") then
  165.             do
  166.                 call showerror('No signature configured in either conference, bbs or global settings! Please correct this in THOR or turn off signature adding in AWebMailTo.thor.')
  167.                 call close(fh)
  168.                 address command 'c:delete >NIL: 'tempfile''
  169.                 exit
  170.             end
  171.             else sig = GLOBD.SIGNATURE
  172.         end
  173.         else sig = BBSD.SIGNATURE
  174.     end
  175.     else sig = CONFD.SIGNATURE
  176.  
  177.     drop CONFD.; drop BBSD.; drop GLOBD.
  178.  
  179.     if(sig ~= "") then
  180.     do
  181.     /* signature may be a filename */
  182.  
  183.         if(exists(sig)) then
  184.         do
  185.             call open(sigfh, sig, R)
  186.  
  187.             do until eof(sigfh)
  188.                 call writeln(tmp, readln(sigfh))
  189.             end
  190.  
  191.             call close(sigfh)
  192.         end
  193.         else call writeln(tmp, sig) /* or just a string */
  194.     end
  195. end
  196.  
  197. call close(tmp)
  198.  
  199. /* fill out some more variables that BBSREAD require */
  200.  
  201. EVENT.CONFERENCE = MailConfName
  202. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  203.  
  204. /* write the event */
  205.  
  206. WRITEBREVENT bbsname '"'MailSystem'"' event 0 stem EVENT
  207. if(rc ~= 0) then
  208. do
  209.     call showerror('WRITEBREVENT BBSRead command failed: ' || BBSREAD.LASTERROR)
  210.     call close(fh)
  211.     address command 'c:delete >NIL: 'tempfile''
  212.     exit
  213. end
  214.  
  215. call close(fh)
  216.  
  217. address command 'c:delete >NIL: 'tempfile''
  218.  
  219. if upper(sendevent) = "Y" then call send
  220.  
  221. exit 0
  222.  
  223. /* sophisticated errorhandling :-) */
  224.  
  225. showerror: procedure expose MailSystem MailConfName AddSignature Editor
  226. parse arg errormsg
  227.  
  228. p=show('P',,)
  229. if(pos('AWEB.', p) > 0) then awebport = word(substr(p, pos('AWEB.', p)), 1)
  230. else return
  231.  
  232. call open(err, "T:AWebMailTo.thor.error.html", W)
  233. call writeln(err, "<HTML><HEAD><TITLE>AWebMailTo.thor encountered an error</TITLE></HEAD><BODY><H1>Sending mail aborted</H1>" || errormsg || "<P>Please remember to verify the following settings:<PRE>MailSystem = '" || MailSystem || "'" || '0a'x || "MailConfName = '" || MailConfName || "'" || '0a'x || "AddSignature = '" || AddSignature || "'" '0a'x || "Editor = '" || Editor || "'" '0a'x || "</PRE>If they are wrong, edit AWebMailTo.thor and correct them. <hr> If this should happen to be an erroneous error, don't hesitate to contact the author, <A HREF=" || '"' || "http://www.geocities.com/SiliconValley/8315" || '"' || ">Shaun Downend</A>, preferably by <A HREF=" || '"' || "mailto:shaund@amiganut.demon.co.uk" || '"' || ">email</A>.")
  234. call close(err)
  235.  
  236. address(awebport)
  237. 'OPEN URL file://localhost/T:AWebMailTo.thor.error.html'
  238. return
  239.  
  240. send:
  241.  
  242. If Show('p', 'AMITCP') | Show('p', 'MIAMI.1') = 1 then
  243. do
  244.     address BBSREAD
  245.     GETBBSDATA SystemName stem BBSDATA
  246.     if BBSDATA.NUMEVENTS ~= 0 then
  247.     address command 'run >NIL: `getenv thor/thorpath`bin/SendTCP 'MailSystem' pubscreen=Workbench'
  248. end
  249. return
  250.